

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  
  <title>Lab3 Report &mdash; lab2  documentation</title>
  

  
  <link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="_static/pygments.css" type="text/css" />

  
  

  
  

  

  
  <!--[if lt IE 9]>
    <script src="_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
        <script src="_static/jquery.js"></script>
        <script src="_static/underscore.js"></script>
        <script src="_static/doctools.js"></script>
        <script src="_static/language_data.js"></script>
    
    <script type="text/javascript" src="_static/js/theme.js"></script>

    
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="#" class="icon icon-home"> lab2
          

          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <!-- Local TOC -->
              <div class="local-toc"><ul>
<li><a class="reference internal" href="#">Lab3 Report</a></li>
<li><a class="reference internal" href="#introduction">Introduction</a></li>
<li><a class="reference internal" href="#materials-and-methods">Materials and Methods</a></li>
<li><a class="reference internal" href="#results">Results</a></li>
<li><a class="reference internal" href="#pros-cons">Pros&amp;Cons</a></li>
<li><a class="reference internal" href="#discussions">Discussions</a></li>
<li><a class="reference internal" href="#references">References</a></li>
</ul>
</div>
            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="#">lab2</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          

















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="#" class="icon icon-home"></a> &raquo;</li>
        
      <li>Lab3 Report</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
          
            <a href="_sources/index.md.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="lab3-report">
<h1>Lab3 Report<a class="headerlink" href="#lab3-report" title="Permalink to this headline">¶</a></h1>
<p>Title:  Lab3 The Service Layer</p>
<p>Author: 黄文心、朱彩凤、朱倩</p>
<p>Date: 2021/6/17</p>
</div>
<div class="section" id="introduction">
<h1>Introduction<a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h1>
<p>In this experiment , you are going to implement a service layer in services.py for EnglishPal, which provides a core service called read. This service would choose a suitable article for a user to read.and Practice Test-driven development</p>
</div>
<div class="section" id="materials-and-methods">
<h1>Materials and Methods<a class="headerlink" href="#materials-and-methods" title="Permalink to this headline">¶</a></h1>
<p>In this lab, we study the dependency inversion ,High level module should not rely on low level module, both of them should rely on its abstraction; Abstraction should not rely on details; Details should rely on abstraction.</p>
<p>With object-relational mapper (ORM) provided by SQLAlchemy, we can map a class to a database table, and map an object of that class to a row in the databasetable and o create four database tables for EnglishPal. With SQLAlchemy’s ORM, we can avoid directly using any raw SQL statements,let ORM depend on the domain model,but not the other way around.</p>
<p>Use FOREIGN KEY  to understand the relationship between two tables.</p>
<p>On the basis of Experiment 2,implement a service layer in services.py for EnglishPal, which provides a core service called read, The function read takes user,user repo,article repo,session four arguments and returns an article ID if the user has been successfully assigned with an article to read.</p>
<p>By running pytest -v -s test services.py  command  make all the fifive test cases defifined in test services.py.Pytest is a very mature full-function Python testing framework, which has the following characteristics:Simple and flexible, easy to start,Support parameterization.It can support simple unit test and complex function test, and can also be used for automatic testing such as selenium/appium, and pytest + request Pytest has many third-party plug-ins, and can be customized for extension. It is better to use, such as pytest selenium (integrated selenium), pytest HTML (perfect HTML test report generation), pytest rerun failures (repeated execution of failure cases), pytest xdist (multi CPU distribution), etc
Skip and xfail processing of test cases.It’s good to integrate with Jenkins
Report framework - allow also supports pytest.</p>
</div>
<div class="section" id="results">
<h1>Results<a class="headerlink" href="#results" title="Permalink to this headline">¶</a></h1>
<p>The running results are in the file.</p>
</div>
<div class="section" id="pros-cons">
<h1>Pros&amp;Cons<a class="headerlink" href="#pros-cons" title="Permalink to this headline">¶</a></h1>
<ul class="simple">
<li><p>Pros:This project framework is clearly structured,code easy to analyze and maintain and improves functions properly</p></li>
<li><p>Cons:Basic functions are fully determined, with low room for further innovation and many places hava to be improved</p></li>
</ul>
</div>
<div class="section" id="discussions">
<h1>Discussions<a class="headerlink" href="#discussions" title="Permalink to this headline">¶</a></h1>
<p>Use Sqlalchemy’s ORM as a web application to improve learners’ vocabulary. The abstraction of code does not depend on the type of database and the uniqueness of database itself. It provides powerful general statements and types. It doesn’t need to consider the database you choose and its manufacturer’s implementation. Sqlalchemy also allows you to transfer data logic from Oracle or PostgreSQL to the application’s database. It standardizes and escapes the database before submitting operations to it. This avoids some common problems, such as database injection attacks.</p>
<p>Try running cases again
When we do interface testing, we will encounter 503 or short-term network fluctuations, which will lead to the failure of case operation, which is not the expected result. At this time, we can solve it by retrying to run cases.
Install pytest rerun failures:
pip install -U pytest-rerunfailures
Operation mode:
pytest test_ se.py –reruns NUM
Num fills in the number of retries.</p>
</div>
<div class="section" id="references">
<h1>References<a class="headerlink" href="#references" title="Permalink to this headline">¶</a></h1>
<p>[1] <a class="reference external" href="https://thehackpost.com/a-brief-guide-how-to-write-a-computer-science-lab-report.html">A Brief Guide How to Write a Computer Science Lab Report</a></p>
<p>[2] <a class="reference external" href="https://readthedocs.org/">Read the Docs</a>`<a class="reference external" href="#"></a></p>
</div>


           </div>
           
          </div>
          <footer>

  <hr/>

  <div role="contentinfo">
    <p>
        &#169; Copyright 2021, zcf.

    </p>
  </div>
    
    
    
    Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    
    provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>
        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>